<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>{BEESCRM:$title}</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui, user-scalable=no">
    <meta http-equiv="cleartype" content="on">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/assets/complaint/css/style.css">
    <link rel="stylesheet" href="/assets/complaint/css/layer.css">
</head>
<body>
<div class="wrapper">
    <div class="header header2 text-center">
        <a href="javascript:history.back(-1);" class="iconfont icon-zuo left"></a>
        <div class="font-16">评价</div>
    </div>
    <form id="commentform" action="/Complaint/Common/doComment/irs_id/{BEESCRM:$irs_id}">
        <input id="restaurant_id" name="restaurant_id" value="{BEESCRM:$restaurant_id}" type="hidden" style="display: none">
        <div class="content padding-12">
            <div class="list">
                <div>
                    <span class="gray ">口味：</span>
                <span class="star">
                    <span class="iconfont icon-xingxing font-20"></span>
                    <span class="iconfont icon-xingxing font-20"></span>
                    <span class="iconfont icon-xingxing font-20"></span>
                    <span class="iconfont icon-xingxing font-20"></span>
                    <span class="iconfont icon-xingxing font-20"></span>
                     <input type="text" name="taste_score" id="taste_star" style="display: none;"/>
                </span>
                </div>
                <div>
                    <span class="gray ">服务：</span>
                <span class="star">
                    <span class="iconfont icon-xingxing font-20"></span>
                    <span class="iconfont icon-xingxing font-20"></span>
                    <span class="iconfont icon-xingxing font-20"></span>
                    <span class="iconfont icon-xingxing font-20"></span>
                    <span class="iconfont icon-xingxing font-20"></span>
                     <input type="text" name="service_score" id="service_star" style="display: none;"/>
                </span>
                </div>
                <div>
                    <span class="gray ">环境：</span>
                <span class="star">
                    <span class="iconfont icon-xingxing font-20"></span>
                    <span class="iconfont icon-xingxing font-20"></span>
                    <span class="iconfont icon-xingxing font-20"></span>
                    <span class="iconfont icon-xingxing font-20"></span>
                    <span class="iconfont icon-xingxing font-20"></span>
                     <input type="text" name="environment_score" id="environment_star" style="display: none;"/>
                </span>
                </div>
            </div>
            <div class="list">
            <textarea class="font-12 gray2" name="content" id="comment" cols="30" rows="10"
                      placeholder="对公寓整体感觉怎么样？来说说吧~"></textarea>
            </div>
            <div class="list">
                <div class="load-img text-center">
                    <div class="img" id="show_img">
                        <div class="delete iconfont icon-shanchu hide" id="delete"></div>
                    </div>
                    <div class="load ">+</div>
                </div>
                <input type="file" class="file hide" onchange="showPreview(this)" name="inputfile" id="picture">
            </div>
        </div>
        <a href="javascript:;" class="btn text-center font-16">提交评论</a>
    </form>
</div>
</body>
<script src="/assets/complaint/js/public.js"></script>
<script src="/assets/complaint/js/layer.js"></script>
<script src="/assets/complaint/js/jquery-2.1.0.min.js"></script>
<script>
    $('.star').on('click', '.icon-xingxing', function () {
        var num = $(this).index() + 1;
        $(this).addClass('xingxing').prevAll().addClass('xingxing');
        $(this).nextAll().removeClass('xingxing');
        //给隐藏域input赋值
        $(this).siblings('input').val(num);
    })
    $('.load').click(function () {


        $('.file').click();

    });

    function showPreview(source) {
        var file = source.files[0];
        if (window.FileReader) {  //当浏览器支持fileReader
            var fr = new FileReader();
            fr.onloadend = function (e) {
                var img = document.createElement("img");
                img.onerror = null;
                img.src = e.target.result;
                img.alt = '';
                img.id = 'pic';
                //$("#portrait").attr('src', e.target.result);
                $("#show_img").append(img);
                document.getElementById("delete").style.display = "block";

            };
            fr.readAsDataURL(file);
        }
    }


    /*   $(".img").mousedown(function() {
     timeout = setTimeout(function() {
     $(".delete").removeClass('hide');
     }, 2000);
     });
     $(".img").mouseup(function() {
     clearTimeout(timeout);
     $(".delete").removeClass('hide');
     });*/
    $('.btn').click(function () {


        var restaurant_id = $('#restaurant_id').val();
        var taste_star = $('#taste_star').val();
        var service_star = $('#service_star').val();
        var environment_star = $('#environment_star').val();
        var img = $('#picture').val();
        var content = $('#comment').val();
        if (taste_star == 0) {
            fm.alert('请对口味进行评价');
            return;
        }
        if (service_star == 0) {
            fm.alert('请对服务进行评价');
            return;
        }
        if (environment_star == 0) {
            fm.alert('请对环境进行评价');
            return;
        }
        if (!content) {
            fm.alert('请输入评论内容');
            return;
        }

        //提交表单,不要使用ajax

        // 使用ajax提交表达数据,包括file文件
        var form = new  FormData(document.getElementById("commentform"));

        $.ajax({
//            data: $('#commentform').serialize(),
            data:form,
            method: 'post',
            processData:false,
            contentType:false,
            dataType: 'json',
            url: '/Complaint/Common/doComment/irs_id/{BEESCRM:$irs_id}',
            success: function (result) {
                if (result.status == 'S') {
                    fm.alert('评论成功');
                    window.location.href="/Complaint/Common/index/irs_id/{BEESCRM:$irs_id}";
                    $('#add_modal').hide();
                } else {
                    fm.alert('评论失败');
                    reload();
                }
            }
        })
    });

    $('#delete').click(function () {
        document.getElementById("picture").value = "";
        $('#pic').remove();
        document.getElementById("delete").style.display = "none";
    });

    function reload1(){
        setTimeout('location.reload()', 2000);
    }
</script>


</html>